package cn.itrip.order.service;

import cn.itrip.vo.comment.ItripHotelDescVO;
import cn.itrip.vo.hotel.ItripSearchPolicyHotelVO;
import cn.itrip.vo.hotel.ItripSearchDetailsHotelVO;
import cn.itrip.vo.hotel.HotelVideoDescVO;
import cn.itrip.vo.hotel.ItripSearchFacilitiesHotelVO;
import cn.itrip.dao.*;
import cn.itrip.pojo.*;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Created by LENOVO on 2018/8/24.
 */
@Service
public class HotelServiceImpl implements HotelService {
    @Resource
    private ItripAreaDicMapper itripAreaDicMapper;
    @Resource
    private ItripLabelDicMapper itripLabelDicMapper;
    @Resource
    private ItripHotelMapper itripHotelMapper;
    @Resource
    private ItripHotelFeatureMapper itripHotelFeatureMapper;
    @Resource
    private ItripHotelTradingAreaMapper itripHotelTradingAreaMapper;
    /**
     * 根据条件查询热门城市
     * @param condition
     * @return
     * @throws Exception
     */
    @Override
    public List<ItripAreaDic>  getHotCityByCondition(Map condition) throws Exception {

        return itripAreaDicMapper.selectHotCityByCondition(condition);
    }

    /**
     * 查询商圈
     * @param condition
     * @return
     * @throws Exception
     */
    @Override
    public List<ItripAreaDic> getTradeAreaByCondition(Map condition) throws Exception {

        return itripAreaDicMapper.selectTradeAreaByCondition(condition);
    }

    /**
     * 查询酒店所有特色
     * @param condition
     * @return
     * @throws Exception
     */
    @Override
    public List<ItripLabelDic> getHotelFeatureByCondition(Map condition) throws Exception {

        return itripLabelDicMapper.selectHotelFeatureByCondition(condition);
    }

    /**
     * 查询视频描述信息
     * @param condition
     * @return
     * @throws Exception
     */
    @Override
    public HotelVideoDescVO getVideoDescByHotelId(Map condition) throws Exception {

        HotelVideoDescVO hotelVideoDescVO = new HotelVideoDescVO();

        List<ItripHotelTradingArea> itripAreaDicList = itripHotelTradingAreaMapper.getHotelAreaByHotelId(condition);
        List<String> itripAreaDicList1 = new ArrayList<>();
        for (ItripHotelTradingArea itripHotelTradingArea:itripAreaDicList) {

            itripAreaDicList1.add(itripHotelTradingArea.getName());
        }
        hotelVideoDescVO.setTradingAreaNameList(itripAreaDicList1);

        List<ItripHotelFeature> itripHotelFeatureList= itripHotelFeatureMapper.getHotelFeatureByHotelId(condition);
        List<String> itripHotelFeatureList1=new ArrayList<String>();
        for(ItripHotelFeature itripHotelFeature:itripHotelFeatureList)
        {
            itripHotelFeatureList1.add(itripHotelFeature.getName());
        }
        hotelVideoDescVO.setHotelFeatureList(itripHotelFeatureList1);

        ItripHotel itripHotel=itripHotelMapper.selectByPrimaryKey(Long.parseLong(condition.get("id").toString()));
        hotelVideoDescVO.setHotelName(itripHotel.getHotelname());

        return hotelVideoDescVO;
    }

    /**
     * 根据酒店id查询特色和介绍
     * @param condition
     * @return
     * @throws Exception
     */
    @Override
    public List<ItripSearchDetailsHotelVO> getHotelDetails(Map condition) throws Exception {

        List<ItripSearchDetailsHotelVO> itripSearchDetailsHotelVOList =new ArrayList<>();
        ItripSearchDetailsHotelVO vo = new ItripSearchDetailsHotelVO();
        vo.setName("酒店介绍");
        vo.setDescription(itripHotelMapper.selectByPrimaryKey(Long.parseLong(condition.get("id").toString())).getDetails());
        itripSearchDetailsHotelVOList.add(vo);
        List<ItripHotelFeature> itripHotelFeatureList= itripHotelFeatureMapper.getHotelFeatureByHotelId(condition);
        for(int i=0;i<itripHotelFeatureList.size();i++)
        {
            ItripHotelFeature itripHotelFeature=itripHotelFeatureList.get(i);
            ItripSearchDetailsHotelVO itripSearchDetailsHotelVO1 =new ItripSearchDetailsHotelVO();
            itripSearchDetailsHotelVO1.setName(itripHotelFeature.getName());
            itripSearchDetailsHotelVO1.setDescription(itripHotelFeature.getDescription());
            itripSearchDetailsHotelVOList.add(itripSearchDetailsHotelVO1);
        }
        return itripSearchDetailsHotelVOList;
    }
    /**
     * 根据酒店id查询酒店设备
     * @param condition
     * @return
     */
    @Override
    public ItripSearchFacilitiesHotelVO getHotelFacilities(Map condition) throws Exception {
        ItripSearchFacilitiesHotelVO itripSearchFacilitiesHotelVO=new ItripSearchFacilitiesHotelVO();
        ItripHotelWithBLOBs itripHotelWithBLOBs=itripHotelMapper.selectByPrimaryKey(Long.parseLong(condition.get("id").toString()));
        itripSearchFacilitiesHotelVO.setFacilities(itripHotelWithBLOBs.getFacilities());
        return itripSearchFacilitiesHotelVO;
    }
    /**
     * 根据酒店id查询酒店政策
     * @param condition
     * @return
     */
    @Override
    public ItripSearchPolicyHotelVO getHotelHotelPolicy(Map condition) throws Exception {
        ItripHotelWithBLOBs itripHotelWithBLOBs=itripHotelMapper.selectByPrimaryKey(Long.parseLong(condition.get("id").toString()));
        ItripSearchPolicyHotelVO itripSearchPolicyHotelVO=new ItripSearchPolicyHotelVO(itripHotelWithBLOBs.getHotelpolicy());
        return itripSearchPolicyHotelVO;
    }

    /**
     * 根据酒店id查询目标VO
     * @param id
     * @return
     * @throws Exception
     */
    @Override
    public ItripHotelDescVO selectDescVOByHotelId(Long id) throws Exception {

        if(id == null || id.equals("")){
            throw new Exception("参数错误！");
        }
        ItripHotel itripHotel = itripHotelMapper.selectByPrimaryKey(id);

        ItripHotelDescVO itripHotelDescVO = null;
        try {
            itripHotelDescVO = new ItripHotelDescVO();
        } catch (Exception e) {
            e.printStackTrace();
            throw new Exception("查询失败！");
        }
        itripHotelDescVO.setHotelId(itripHotel.getId());
        itripHotelDescVO.setHotelLevel(itripHotel.getHotellevel());
        itripHotelDescVO.setHotelName(itripHotel.getHotelname());
        return itripHotelDescVO;
    }
}
